home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1995 May / cd Ware (Juegos) Epimundo.iso / DOS / C / WLIB.ZIP / WDOS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-21  |  2.4 KB  |  105 lines

  1. #include <dir.h>
  2. #include <dos.h>
  3. #include <stdio.h>
  4. #include <WTime.h>
  5. #include <WDOS.h>
  6.  
  7. #ifdef MAJORBBS
  8.   extern "C"
  9.     {
  10.       #include <dosface.h>
  11.     }
  12. #endif
  13.  
  14. #pragma hdrstop
  15.  
  16. // copyright (c) 1993 by Paul Wheaton
  17.  
  18. #ifdef MAJORBBS
  19.  
  20.   void LoadDirectory(const char* DirMask,Directory& D)
  21.     {
  22.       fndblk FF;
  23.       Bool Found=(fnd1st(&FF,(char*)DirMask,0)==1);
  24.       while(Found)
  25.         {
  26.           DirElementType* DE=(DirElementType*)malloc(sizeof(DirElementType));
  27.           if (DE==NULL) FatalError("dir mem new");
  28.           strcpy(DE->Name,FF.name);
  29.           D.Add(*DE);
  30.           Found=(fndnxt(&FF)==1);
  31.         }
  32.     }
  33.  
  34. #else
  35.  
  36.   static int UnpackInt(int X,int StartBit, int StopBit)
  37.     {
  38.       X>>=StartBit;
  39.       StopBit-=StartBit;
  40.       int Mask=(1<<(StopBit+1))-1;
  41.       X&=Mask;
  42.       return X;
  43.     }
  44.  
  45.   static Moment MakeAMoment(const ffblk& F)
  46.     {
  47.       int Year=UnpackInt(F.ff_fdate,9,15)+1980;
  48.       int Month=UnpackInt(F.ff_fdate,5,8);
  49.       int Day=UnpackInt(F.ff_fdate,0,4);
  50.       int Hour=UnpackInt(F.ff_ftime,11,15);
  51.       int Minute=UnpackInt(F.ff_ftime,5,10);
  52.       JulianDate J(Year,Month,Day);
  53.       Moment M(J,Hour,Minute);
  54.       return M;
  55.     }
  56.  
  57.   void LoadDirectory(const char* DirMask,Moment StartMoment,Directory& D)
  58.     {
  59.       ffblk FF;
  60.       Bool Found=(findfirst(DirMask,&FF,0)==0);
  61.       while(Found)
  62.         {
  63.           Moment M=MakeAMoment(FF);
  64.           if (M>=StartMoment)
  65.             {
  66.               DirElementType* DE=new DirElementType;
  67.               if (DE==NULL) FatalError("cannot allocate for dir");
  68.               strcpy(DE->Name,FF.ff_name);
  69.               DE->M=M;
  70.               D.Add(*DE);
  71.             }
  72.           Found=(findnext(&FF)==0);
  73.         }
  74.     }
  75.  
  76.   void LoadDirectory(const char* DirMask,Directory& D)
  77.     {
  78.       ffblk FF;
  79.       Bool Found=(findfirst(DirMask,&FF,0)==0);
  80.       while(Found)
  81.         {
  82.           DirElementType* DE=new DirElementType;
  83.           if (DE==NULL) FatalError("dir mem new");
  84.           strcpy(DE->Name,FF.ff_name);
  85.           D.Add(*DE);
  86.           Found=(findnext(&FF)==0);
  87.         }
  88.     }
  89.  
  90.   long DirCount(const char* DirMask)
  91.     {
  92.       long Quan=0;
  93.       ffblk FF;
  94.       Bool Found=(findfirst(DirMask,&FF,0)==0);
  95.       while(Found)
  96.         {
  97.           Quan++;
  98.           Found=(findnext(&FF)==0);
  99.         }
  100.       return Quan;
  101.     }
  102.  
  103. #endif
  104.  
  105.